package com.example.trb.util.result;

import com.example.trb.util.DateFormatUtil;
import lombok.Data;

import java.util.Date;

@Data
public class CommonResult {
    private int code;
    private String message;
    private Object data;
    private String datetime;

    public CommonResult() {
        this.datetime = DateFormatUtil.dateTimeToString(new Date());
    }

    public CommonResult(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.datetime = DateFormatUtil.dateTimeToString(new Date());
    }

    public static CommonResult common(int code, String message, Object data) {
        CommonResult result = new CommonResult();
        result.code = code;
        result.message = message;
        result.data = data;
        result.datetime = DateFormatUtil.dateTimeToString(new Date());
        return result;
    }

    public static CommonResult success(Object data) {
        CommonResult result = new CommonResult();
        result.setCode(SysReturnCode.OK.code);
        result.setMessage(SysReturnCode.OK.message);
        result.setData(data);
        return result;
    }

    public static CommonResult fail(int code, String message) {
        CommonResult result = new CommonResult();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static CommonResult fail(int code, String message, Object data) {
        CommonResult result = new CommonResult();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
